CC          =   gcc
CFLAGS      =   -w
RUN         =   exe_obj

SRCDIR      =   src
OBJDIR      =   build

# get all source, ./src/main.c => src/main.c
SOURCES =   $(shell find $(SRCDIR) -name *.c)

# get all header
INCLUDES    =   $(shell find $(SRCDIR) -name *.h)

# set obj, src/xxx.c => build/xxx.o
OBJECTS     =   $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)

# dir to make
DIRS        =   $(OBJDIR) $(OBJDIR)/lib
BINOBJ      =   $(OBJDIR)/exe_obj

all: MKDIRS $(BINOBJ)

MKDIRS:
    mkdir -p $(DIRS)
 
clean:
    rm -rf $(DIRS)

$(BINOBJ):$(OBJECTS)
    $(CC) $(CFLAGS) $^ -o $@

$(OBJDIR)/%.o: $(SRCDIR)/%.c
    $(CC)  $(CFLAGS) -c $^ -o $@

debug:
    @echo $(SOURCES)
#   @echo $(INCLUDES)
    @echo $(OBJECTS)
#   @echo $(DIRS)

test:
    @echo 'no test script'
run:
    ./$(BINOBJ)
usage:
    @echo 'compile src/xxx => build/xxx, keep structure'